//
//  ViewController4.swift
//  SWIFTLEARN
//
//  Created by chichaojituan521 on 2017/6/7.
//  Copyright © 2017年 linch. All rights reserved.
//

import UIKit

class ViewController4: UIViewController {

    let numOfPages = 3
    let pageWidth = Int(UIScreen.main.bounds.width)
    let pageHeight = Int(UIScreen.main.bounds.height) - 64
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        //scrollView的初始化
        let scrollView = UIScrollView()
        scrollView.frame = self.view.bounds
        //为了让内容横向滚动，设置横向内容宽度为3个页面的宽度总和
        scrollView.contentSize = CGSize(width: pageWidth * numOfPages,
                                        height: pageHeight)
        scrollView.isPagingEnabled = true
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.showsVerticalScrollIndicator = false
        scrollView.scrollsToTop = false
        
        //添加子页面
        for i in 0..<numOfPages{
            let myViewController = MyViewController(number:(i+1))
            myViewController.view.frame = CGRect(x:pageWidth*i, y:0,
                                                 width:pageWidth, height:pageHeight)
            scrollView.addSubview(myViewController.view)
        }
        self.view.addSubview(scrollView)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

   }
